﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leffaetsin.Services;
using System.IO;
using System.IO.IsolatedStorage;
using System.Diagnostics;
using Leffaetsin.Views.Home.Models;
using System.Net;
using System.IO.Compression;
using Leffaetsin.Models;

namespace Leffaetsin.Controllers
{
    public class HomeController : Controller
    {
        //[OutputCache(Duration = 86400, VaryByParam = "none")]
        public ActionResult Debug()
        {
            MovieService.ForceRefreshMovieData();
            var model = new HomeModel()
                            {
                                Areas = AreaService.GetAreas(),
                                Movies = MovieService.GetMovies("Pääkaupunkiseutu")
                            };
            return View(model);
        }

        [OutputCache(Duration = 3600, VaryByParam = "none")]
        public ViewResult Index()
        {
            return View(AreaService.GetAreas());
        }


        [OutputCache(Duration = 3600, VaryByParam = "area")]
        public ViewResult Movies(string area)
        {
            var model = MovieService.GetMovies(area);
            return View(model);
        }

        [OutputCache(Duration = 3600, VaryByParam = "area;movie")]
        public ActionResult Movie(string area, string movie)
        {
            movie = movie.Replace("_", " ");
            // TODO: parempi eerror handling!
            if (String.IsNullOrEmpty(area) || String.IsNullOrEmpty(movie))
            {
                return RedirectToAction("Index");
            }

            return View(MovieService.GetMovie(movie, area));
        }
    }
}
